Contents | Index | < Browse | Browse >
LETTERfgetsULETTER
Reads a line from a file.
Overview
#include <stdio.h>
p = fgets(buffer, len, fp);
char *p; // buffer pointer or zero
char *buffer; // pointer to buffer
int len; // size of buffer
FILE *fp; // file pointer
Portability
ANSI
Description
"fgets" reads a line with max. "len-1" chars from "fp" and places these
including a terminating zero byte in "buffer". The routine stops reading at
a linefeed ('\n') or at the end of the file (EOF). In both cases however
the character won't be put in the buffer.
Returns
If the end of the file has already been passed or an error occured "fgets"
returns zero, otherwise the "buffer" address. In case of an error "errno"
can be used to obtain the error code.
See also
feof , ferror , fgetc , fopen , fputs , fread , gets